<template>
	<view>
		<tui-sticky :scrollTop="scrollTop" stickyHeight="51px" container>
			<view class="padding bg-white" slot="header" ref="sticky">
				<u-search @search="list" placeholder="关键字查询" v-model="pageRequest.condition.keywords" :show-action="false"></u-search>
			</view>
			<template slot="content">
				<view class="margin-top">
					<view class="solid-bottom bg-white" v-for="(item, index) in pageData.content" :key="item.id">
						<u-cell-item
							:title-style="{ width: '100%' }"
							icon="file-text"
							:title="item.user"
							:arrow="true"
							arrow-direction="right"
							@click="navTo(`accesslog-info?info=${encodeURIComponent(JSON.stringify(item))}`)"
						>
							<view slot="label">
								<view class="text-wrap">路径：{{ item.path }}</view>
								<view>时间：{{ item.createTime }}</view>
							</view>
						</u-cell-item>
					</view>
					<u-loadmore :status="pageData.page < pageData.pages ? 'loading' : 'nomore'" bg-color="" class="padding" />
				</view>
			</template>
		</tui-sticky>
	</view>
</template>

<script>
export default {
	onLoad: function(option) {
		this.list(true);
	},
	onPullDownRefresh: function() {
		this.list(true);
	},
	onReachBottom: function() {
		this.list();
	},
	data() {
		return {
			scrollTop: 0, // 滚动高度
			pageRequest: {
				page: 1,
				rows: 15,
				sort: 'createTime:desc',
				condition: {}
			},
			pageData: {
				page: 1,
				pages: 1,
				content: []
			}
		};
	},
	//页面滚动执行方式
	onPageScroll(e) {
		this.scrollTop = e.scrollTop;
	},
	methods: {
		navTo: function(url) {
			uni.navigateTo({
				url: url
			});
		},
		list: function(first) {
			if (first) {
				this.pageRequest.page = 1;
			} else {
				if (this.pageData.page < this.pageData.pages) {
					this.pageRequest.page = this.pageRequest.page + 1;
				} else {
					return;
				}
			}
			this.$request.post(
				`/admin/sys/accesslog/list`,
				this.pageRequest,
				res => {
					let pageData = res.data || {};
					if (this.pageRequest.page > 1) {
						pageData.content = (this.pageData.content || []).concat(pageData.content);
					}
					this.pageData = pageData;
				},
				false,
				true,
				true
			);
		}
	}
};
</script>

<style lang="scss" scoped></style>
